import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Card, Button, Input, message } from 'antd';
import router from 'umi/router';
import PageHeaderWrapper from '@/components/PageHeaderWrapper'; // 引入头部组件
import LocalPolicy from './ProvidentFund/Index';

const FormItem = Form.Item;

@connect(({ localpolicy }) => ({
  localpolicy,
}))
@Form.create()
class BasicList extends PureComponent {
  state = {
    current: 0,
  };

  componentDidMount() {
    const { dispatch } = this.props;
    dispatch({
      type: 'localpolicy/getDictCode',
      payload: ['BIZ_ACCU_TYPE', 'CARRY_RULE'],
    });
    dispatch({
      type: 'localpolicy/clearFunData',
      payload: {},
    });
  }

  prev = () => {
    const { localpolicy } = this.props;
    const { current } = this.state;
    const currents = current - 1;
    this.setState({ current: currents });
    if (localpolicy.providentFundPolicyId) {
      router.goBack();
    } else {
      message.warning(`公积金政策明细缺失，不可保存`);
    }
  };

  render() {
    const { form, localpolicy } = this.props;
    const formItemLayout2 = {
      labelCol: { md: { span: 10 } },
      wrapperCol: { md: { span: 5 } },
    };
    const { getFieldDecorator } = form;

    return (
      <div>
        <PageHeaderWrapper />
        <Card style={{ marginTop: 12, marginLeft: 12, marginRight: 12 }}>
          <div style={{ marginTop: 22 }}>
            <FormItem {...formItemLayout2} label="组合名称">
              {getFieldDecorator('accuLsPkgName', {
                rules: [{ required: true, message: '请输入组合名称' }],
              })(
                <Input
                  placeholder="请输入组合名称"
                  maxLength={30}
                  disabled={String(localpolicy.providentFundPolicyId) !== ''}
                />
              )}
            </FormItem>
          </div>
          <div style={{ margin: '70px 30% 0 25%' }}>
            <LocalPolicy
              {...this.props}
              isprovidentFund={2}
              isaddBtn={1}
              insuranceInformationData={localpolicy.insuranceInformationData}
            />
          </div>

          <p style={{ textAlign: 'center' }}>
            <Button style={{ marginLeft: 30 }} size="large" onClick={() => this.prev()}>
              完成
            </Button>
          </p>
        </Card>
      </div>
    );
  }
}
const BasicListFrom = Form.create()(BasicList);
export default BasicListFrom;
